#coding=utf-8
import os
from appium import webdriver

# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)
#APP的基本设置
desired_caps = {}
#设备的系统
desired_caps['device'] = 'Android'
#设备平台的名字
desired_caps['platformName'] = 'Android'
#设备的名字
desired_caps['deviceName'] = 'emulator-5554'
#浏览器名称
desired_caps['browserName'] = ''
#系统的版本号
desired_caps['version'] = '4.4.2'
#放置的APP的路径
desired_caps['app'] = PATH('D:\Apps\ContactManager.apk')
#对应的包名
desired_caps['app-package'] = 'com.example.android.contactmanager'
#对应的activity的名称
desired_caps['app-activity'] = '.ContactManager'

driver = webdriver.Remote('http://127.0.0.1:4755/wd/hub', desired_caps)

el = driver.find_element_by_name("Add Contact")
el.click()

textfields = driver.find_elements_by_class_name("android.widget.EditText")
#textfields = driver.find_elements_by_tag_name("textfield")
textfields[0].send_keys("Woniu Name")
textfields[2].send_keys("someone@woniuxy.com")

driver.find_element_by_name("Save").click()

driver.quit()